package cn.easybuy.service.user;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import cn.easybuy.entity.UserAddress;
import cn.easybuy.mapper.UserMapper;
import cn.easybuy.utils.DataSourceUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.easybuy.entity.User;
@Service
public class UserServiceImpl implements UserService {
	
	private Logger logger = Logger.getLogger(UserServiceImpl.class);
	@Autowired
	private UserMapper um;

	@Override
	public boolean add(User user){
		Integer count=0;
		try {
			count=um.addUser(user);
		}catch (Exception e) {
			e.printStackTrace();
		}finally {
			return  count>0;
		}
	}

	@Override
	public boolean update(User user) {
		Integer count=0;
		try {
			count=um.updateUser(user);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			return  count>0;
		}
	}

	@Override
	public boolean deleteUserById(Integer userId) {
		Integer count=0;
		try {
			count=um.deleteUser(userId);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			return  count>0;
		}
	}

	@Override
	public User getUser(Integer userId, String loginName) {
		User user=null;
		try {
			user=um.getUserById_Name(userId,loginName);
		}catch (Exception e) {
			e.printStackTrace();
		}finally {
			return user;
		}
	}

	@Override
	public List<User> getUserList(Integer currentPageNo, Integer pageSize) {
		List<User> userList=null;
		try {
			userList=um.getUserList((currentPageNo-1)*pageSize,pageSize);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			return userList;
		}
	}

	@Override
	public int count() {
		Integer count=null;
		try {
			count=um.getUserCount();
		}catch (Exception e) {
			e.printStackTrace();
		}finally {
			return count;
		}
	}
}
